package org.scohen.juploadr.uploadapi.flickrrest;

import java.util.prefs.Preferences;

public class FlickrConfiguration {
    private static FlickrConfiguration instance;
    private static final String UPLOAD_COUNT_KEY = "ucount";
    private static final Object lock = new Object();
    private Preferences prefs;

    static {
        instance = new FlickrConfiguration();
    }

    protected FlickrConfiguration() {
        prefs = Preferences.userNodeForPackage(getClass());
    }

    public static FlickrConfiguration getInstance() {

        return instance;
    }

    public int getUploadCount() {
        return prefs.getInt(UPLOAD_COUNT_KEY, 0);
    }

    public synchronized int incrementUploadCount() {
        synchronized (lock) {
            int count = getUploadCount();
            count++;
            setUploadCount(count);
        }
        return getUploadCount();
    }

    public synchronized void setUploadCount(int count) {
        synchronized (lock) {

            prefs.putInt(UPLOAD_COUNT_KEY, count);
        }
    }
}
